home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uniput.zip / STATUS.C < prev    next >
C/C++ Source or Header  |  1992-10-16  |  7KB  |  251 lines

  1. /**************************************************************************\
  2. * status.c - module to support the status bar.
  3. *
  4. *         Steve Firebaugh
  5. *         Microsoft Developer Support
  6. *         Copyright (c) 1992 Microsoft Corporation
  7. *
  8. *
  9. * resized by main frame window.
  10. * text and painting managed in this module.
  11. \**************************************************************************/
  12. #define UNICODE
  13.  
  14. #include <windows.h>
  15. #include "uniput.h"
  16.  
  17.  
  18. /* spacing for the fields in the status bar... */
  19. #define SBORDER 6
  20. #define SFIELD0 160
  21. #define SFIELD1 100
  22.  
  23. /* logfont for the font selected into the static windows on status bar */
  24. LOGFONT logfontsmall = {
  25.       UCFONTHEIGHT /2 ,
  26.       UCFONTWIDTH /2,
  27.        0 ,
  28.        0 ,
  29.      400 ,
  30.        0 ,
  31.        0 ,
  32.        0 ,
  33.        UNICODE_CHARSET ,
  34.        0 ,
  35.        0 ,
  36.        2 ,
  37.        2 ,
  38.       TEXT("Lucida Sans Unicode")};
  39.  
  40.  
  41.  
  42.  
  43. /**************************************************************************\
  44. *
  45. *  function:  StatusWndProc()
  46. *
  47. *  input parameters:  normal window procedure parameters.
  48. *
  49. *  global variables:
  50. \**************************************************************************/
  51. LRESULT CALLBACK StatusWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  52. {
  53. static HFONT hfontStatic;
  54. static HWND hwndStatic0, hwndStatic1;
  55. RECT rect, clientrect;
  56.  
  57.  
  58.   switch (message) {
  59.  
  60.     /**********************************************************************\
  61.     *  WM_CREATE
  62.     *
  63.     * Create two static child windows, and select a font for them.
  64.     \**********************************************************************/
  65.     case WM_CREATE: {
  66.       GetClientRect (hwnd, &clientrect);
  67.  
  68.       hwndStatic0 = CreateWindow(
  69.               TEXT("STATIC"),
  70.               TEXT("File: <none>"),
  71.               WS_CHILD | WS_VISIBLE | SS_CENTER,
  72.               0,0,0,0,
  73.               hwnd, NULL, hInst, 0);
  74.  
  75.  
  76.  
  77.       hwndStatic1 = CreateWindow(
  78.               TEXT("STATIC"),
  79.               TEXT("<text stream>:  "),
  80.               WS_CHILD | WS_VISIBLE | SS_LEFT,
  81.               0,0,0,0,
  82.               hwnd, NULL, hInst, 0);
  83.  
  84.  
  85.  
  86.       hfontStatic = CreateFontIndirect (&logfontsmall);
  87.       SendMessage (hwndStatic0, WM_SETFONT, (WPARAM) hfontStatic, 0);
  88.       SendMessage (hwndStatic1, WM_SETFONT, (WPARAM) hfontStatic, 0);
  89.     } break;
  90.  
  91.  
  92.     /**********************************************************************\
  93.     *  WM_DESTROY
  94.     *
  95.     * free the font we created at WM_CREATE time.
  96.     \**********************************************************************/
  97.     case WM_DESTROY:
  98.       DeleteObject (hfontStatic);
  99.     break;
  100.  
  101.  
  102.     /**********************************************************************\
  103.     *  WM_CTLCOLORSTATIC
  104.     \**********************************************************************/
  105.     case WM_CTLCOLORSTATIC: {
  106.       HDC hdc;
  107.  
  108.       hdc = (HDC) wParam;
  109.       SetBkMode (hdc, TRANSPARENT);
  110.       return (LRESULT)GetStockObject (LTGRAY_BRUSH);
  111.     } break;
  112.  
  113.  
  114.     /**********************************************************************\
  115.     *  WM_SIZE
  116.     *
  117.     * Resize the static controls to stretch them to always fill the status
  118.     *  bar minus some border area.
  119.     \**********************************************************************/
  120.     case WM_SIZE: {
  121.       GetClientRect (hwnd, &clientrect);
  122.  
  123.       rect.left = 2*SBORDER;
  124.       rect.top = clientrect.top + SBORDER;
  125.       rect.right = SFIELD0;
  126.       rect.bottom = clientrect.bottom - SBORDER;
  127.  
  128.       SetWindowPos (hwndStatic0, HWND_TOP,
  129.         rect.left,
  130.         rect.top,
  131.         rect.right - rect.left,
  132.         rect.bottom - rect.top, 0);
  133.  
  134.       rect.left  =  rect.right + 4*SBORDER;
  135.       rect.right = clientrect.right - 2*SBORDER;
  136.  
  137.       SetWindowPos (hwndStatic1, HWND_TOP,
  138.         rect.left,
  139.         rect.top,
  140.         rect.right - rect.left,
  141.         rect.bottom - rect.top, 0);
  142.  
  143.       return TRUE;
  144.     } break;
  145.  
  146.  
  147.  
  148.  
  149.     /**********************************************************************\
  150.     *  WMU_SETFILENAME
  151.     *
  152.     * lParam - pointer to new string.
  153.     *
  154.     \**********************************************************************/
  155.     case WMU_SETFILENAME: {
  156.       LPCTSTR lpctstr;
  157.       TCHAR buffer[100];
  158.  
  159.  
  160.  
  161.       lpctstr = (LPCTSTR) lParam;
  162.       if (lpctstr != NULL)
  163.         wsprintf (buffer, TEXT("File: %s"), lpctstr);
  164.       else
  165.         wsprintf (buffer, TEXT("File: <none>"));
  166.  
  167.  
  168.       SetWindowText (hwndStatic0,buffer);
  169.  
  170.     } break;
  171.  
  172.  
  173. #define MAXCHARS 30
  174.  
  175.     /**********************************************************************\
  176.     *  WMU_CHARACTER
  177.     *
  178.     * lParam - WCHAR value
  179.     *
  180.     * Display a string of characters in the second static window. This is
  181.     *  a FIFO buffer, if we fill it, shift characters to the left, and
  182.     *  set the string back into the static control.
  183.     *
  184.     \**********************************************************************/
  185.     case WMU_CHARACTER: {
  186.       TCHAR buffer[MAXCHARS+1];
  187.       int nchar;
  188.       int i;
  189.  
  190.       GetWindowText (hwndStatic1,buffer, MAXCHARS+1);
  191.       nchar = GetWindowTextLength (hwndStatic1);
  192.  
  193.       if (nchar >= MAXCHARS) {
  194.         nchar = MAXCHARS-1;
  195.         for (i= 0; i<(MAXCHARS-1); i++)
  196.           buffer[i] = buffer[i+1];
  197.       }
  198.  
  199.       buffer[nchar] = (TCHAR) lParam;
  200.       buffer[nchar+1] = (TCHAR) '\000';
  201.  
  202.       SetWindowText (hwndStatic1,buffer);
  203.  
  204.     } break;
  205.  
  206.  
  207.  
  208.     /**********************************************************************\
  209.     *  WM_PAINT
  210.     *
  211.     * Gray background is done automatically, just outline the two static
  212.     *  text windows with 3-D effect.
  213.     \**********************************************************************/
  214.     case WM_PAINT: {
  215.       HDC hdc;
  216.       PAINTSTRUCT ps;
  217.  
  218.       hdc = BeginPaint(hwnd, &ps);
  219.       GetClientRect (hwnd, &clientrect);
  220.  
  221.       /* outline static0 */
  222.       rect.left = 2*SBORDER;
  223.       rect.top = clientrect.top + SBORDER;
  224.       rect.right = SFIELD0;
  225.       rect.bottom = clientrect.bottom - SBORDER;
  226.       InflateRect (&rect, 1, 1);
  227.       FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
  228.       InflateRect (&rect, -1, -1);
  229.       SelectObject (hdc, GetStockObject (WHITE_PEN));
  230.       MoveToEx (hdc, rect.right, rect.top, NULL);
  231.       LineTo (hdc,rect.right, rect.bottom);
  232.       LineTo (hdc,rect.left, rect.bottom);
  233.  
  234.       /* outline static1 */
  235.       rect.left = rect.right + 4*SBORDER;
  236.       rect.right = clientrect.right - 2*SBORDER;
  237.       InflateRect (&rect, 1, 1);
  238.       FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
  239.       InflateRect (&rect, -1, -1);
  240.       SelectObject (hdc, GetStockObject (WHITE_PEN));
  241.       MoveToEx (hdc, rect.right, rect.top, NULL);
  242.       LineTo (hdc,rect.right, rect.bottom);
  243.       LineTo (hdc,rect.left, rect.bottom);
  244.  
  245.       EndPaint (hwnd, &ps);
  246.  
  247.     } return FALSE; /* end WM_PAINT */
  248.   } /* end switch */
  249.   return (DefWindowProc(hwnd, message, wParam, lParam));
  250. }
  251.